#include "test_etimer.h"
#include "cm_uart.h"
#include "cm_demo_uart.h"

static cm_etimer_manager_t test_etimer_manager = {NULL};
static cm_etimer_t test_etimers[10];
static void test_cm_etimer_timeout(cm_etimer_t *timer, void *cb_param)
{
    uint32_t timer_id = (uint32_t)cb_param;
    cm_demo_printf("test_cm_etimer_timeout(timer:%p, para:%p) timer_id=%u\n", (uint32_t)timer, cb_param, timer_id);
}

void cm_test_etimer_operation(unsigned char*cmd[],int len)
{
    if(0 == strncmp("INIT_ETIMER_MANGAER",cmd[2],strlen("INIT_ETIMER_MANGAER")))
    {
        cm_demo_printf("cm_etimer_manager_init ret:%d\n", cm_etimer_manager_init(&test_etimer_manager));
    }
    else if(0 == strncmp("INIT_ETIMER",cmd[2],strlen("INIT_ETIMER")))
    {
        int i = 0;
        for (i = 0; i < 10; ++i)
        {
            cm_demo_printf("cm_etimer_init ret:%d\n",cm_etimer_init(&test_etimers[i], test_cm_etimer_timeout, (void *)i));
        }
    }else if(0 == strncmp("START_ETIMER",cmd[2],strlen("START_ETIMER")))
    {
        int timer = atoi(cmd[3]);
        uint32_t millisec = atoi(cmd[4]);
        cm_demo_printf("cm_etimer_start ret:%d\n",cm_etimer_start(&test_etimer_manager, &test_etimers[timer], millisec));
    }else if(0 == strncmp("RUN_ETIMER_MANAGER",cmd[2],strlen("RUN_ETIMER_MANAGER")))
    {
        cm_etimer_run(&test_etimer_manager);
    }
    else if(0 == strncmp("GET_WAIT_TIME",cmd[2],strlen("GET_WAIT_TIME")))
    {
        cm_demo_printf("cm_etimer_get_wait_time ret:%d\n",cm_etimer_get_wait_time(&test_etimer_manager));
    }
    else if(0 == strncmp("STOP_TIMER",cmd[2],strlen("STOP_TIMER")))
    {
        int timer = atoi(cmd[3]);
        cm_demo_printf("cm_etimer_stop ret:%d\n",cm_etimer_stop(&test_etimers[timer]));
    }    
    else{
        cm_demo_printf("param error!\n");
    }
}
